﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DIPLib.Filters
{
    public class BoundaryExtraction
    {
        public static void doIt(byte[] rgbData, int width, int height)
        {
            byte[] matrix = new byte[9];
            //f[1] = f[3] = f[4] = f[5] = f[7] = 1;
            for (int i = 0; i < 9; i++)
            {
                matrix[i] = 1;
            }
            byte[] rgbDataDes = (byte[])rgbData.Clone();
            Erosion.doIt(rgbDataDes, width, height, matrix);
            int size = width * height;
            for (int i = 0; i < size; i++)
            {
                int sub = rgbDataDes[4 * i] - rgbData[4 * i];
                byte value = (byte)(sub < 0 ? 0 : (sub > 255 ? 255 : sub));
                rgbData[4 * i] = rgbData[4 * i + 1] = rgbData[4 * i + 2] = value;
            }
        }
    }
}
